using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;


namespace TaiLieu
{
    public class UsersDB : Base
    {
        public static Users TestLogin(string userName, string pass, string domain)
        {
            XPCollection<Users> _xpUser = new XPCollection<Users>(KetNoiCSDL.session);
            string pass1 = maHoa.GetMD5HashData(pass);
            string userName1 = maHoa.GetMD5HashData(userName);
            string domain1 = maHoa.GetMD5HashData(domain);
            string filter = ColumUsers._User_name + "='" + userName1 + "' and " + ColumUsers._Pass + "='" + pass1 + "' and " + ColumUsers._web + "='" + domain1 + "'";
            Users users = new Users(KetNoiCSDL.session);
            users = KetNoiCSDL.session.FindObject<Users>(DevExpress.Data.Filtering.CriteriaOperator.Parse(filter));
            if (users != null)
            {
                return users;
            }
            return null;
        }
        /// <summary>
        /// GetMenuById(int id)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //public static Users GetObjectById(int id)
        //{
        //    return KetNoiCSDL.session.FindObject<Users>(DevExpress.Data.Filtering.CriteriaOperator.Parse("Id=" + id.ToString()));
        //}
        //public static Users GetObjectById()
        //{
        //    XPCollection<Users> _xpUser = new XPCollection<Users>(KetNoiCSDL.session);
        //    _xpUser.Filter = null;
        //    return _xpUser[0];
        //}
        public static Users GetObjectByid(int id, bool admin, string domain)
        {
            XPCollection<Users> _xpUsers = new XPCollection<Users>(KetNoiCSDL.session);
            _xpUsers.Filter = FilterById(id, admin, domain);
            try
            {
                return _xpUsers[0];
            }
            catch
            { return null; } //new Category(KetNoiCSDL.session); 
        }
    }
}
